<template>
	<view class="flex flex-1 justify-center align-center position-absolute-full">
		<text>请稍后...</text>
	</view>
</template>

<script>
	// #ifdef H5
	import wx from 'weixin-js-sdk'
	// #endif
	import {
	  mapMutations,
		mapState
	} from 'vuex'
	let app = {}
	// #ifdef MP-WEIXIN || MP-KUAISHOU
	app = getApp({ allowDefault: true}).$vm
	// #endif
	// #ifdef APP-PLUS || H5
	app = getApp({allowDefault: true})
	// #endif
	export default {
		data() {
			return {
				authtoken:"",
				wxcode:""
			};
		},
		onLoad(e) {
			console.log(e)
			if(e.authtoken){
				this.authtoken = e.authtoken
				this.thirdtoken()
			}
			if(e.code){
				this.wxcode = e.wxcode
				this.thirdtoken()
			}
			wx.enableAlertBeforeUnload({
			    message: "确定要退出吗？",
			    success: function (res) {
			      wx.miniProgram.navigateBack({delta: 1}) 
			    },
			    fail: function (errMsg) {
			      console.log("方法注册失败：", errMsg);
			    },  
			});
		},
		async onShow() {
		},
		onBackPress(options) {
			return false
		},  
		computed:{},
		methods: {
			...mapMutations([
			        'login',   
			  ]),
			bindWx(){
				uni.$http.post("/api/user/getWxUserinfo",{
					code:this.wxcode,
				})
				.then((res)=>{
					console.log("res",res)
				})
				.catch(err=>{
					console.log("err",err)
				})
			},
			thirdtoken(){
				uni.$http.post("/api/user/thirdlogin",{
					thirdtoken:this.authtoken,
				})
				.then((res)=>{
					let userinfo = res.data.userinfo;
					this.login(userinfo)
					uni.setStorageSync("token",userinfo.token)
					location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9dff7fd5d70db372&response_type=code&scope=snsapi_userinfo&state=thirdlogin&redirect_uri=https%3A%2F%2Fdashu.api.5gtc.net/h5/pages/common/wx_bind"
					//app.$navigateTo('/pages/user/tx')
				})
				.catch(err=>{
					setTimeout(function() {
						 wx.miniProgram.navigateBack({delta: 1}) 
					}, 1000);
					console.log("err",err)
				})
			}
		}
	}
	
</script>

<style>
</style>